package dk.dtu.android.transport.gps;

import dk.dtu.android.transport.Constants;
import dk.dtu.android.transport.Helpers;
import dk.dtu.android.transport.TransportAPI;
import dk.dtu.android.transport.db.KeyValueTable;
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;
import android.util.Log;

public class MyLocationListener implements LocationListener {

	public static String x;
	public static String y;
	
	public void onLocationChanged(Location loc) {
		try {
			Double latitude = loc.getLatitude()*1000000;
			Double longitude = loc.getLongitude()*1000000;
			
			Log.d("TRANSPORT", "............................................");
			Log.d("TRANSPORT", "Latitude: " + latitude);
			Log.d("TRANSPORT", "Longitude: " + longitude);
			
			x = Integer.toString(longitude.intValue());
			y = Integer.toString(latitude.intValue());
			
			if (TransportAPI.logGPS(x, y, null) == true)
			{
				KeyValueTable.setValue(Constants.LAST_GPS_LOG, Helpers.ToXMLDate(null));
			}
		}
		catch (Exception e)
		{
		}
		finally
		{
			GPSService.mLocMan.removeUpdates(GPSService.mLocList);
			Log.d("TRANSPORT", "Stopped Listening for GPS Location");
		}
	}
	
	public void onProviderDisabled(String provider) { }
	
	public void onProviderEnabled(String provider) { }
	
	public void onStatusChanged(String provider, int status, Bundle extras) { }

} 